<?php
session_start();

 header('Content-Type: text/html; charset=utf-8');

include('funct.php');
html();

if ($_SESSION['uzytk']=='') include('login.php');
if ($_SESSION['config']=='') $_SESSION['config']='panel';
if ($_SESSION['data']=='') $_SESSION['data']=date("Y-m-d");

if ($_POST['wiz_wyw_opis']) $_SESSION['wiz_wyw_opis']=$_POST['wiz_wyw_opis'];
if ($_POST['wiz_badanie_opis']) $_SESSION['wiz_badanie_opis']=$_POST['wiz_badanie_opis'];
if ($_POST['wiz_zalecenia_opis']) $_SESSION['wiz_zalecenia_opis']=$_POST['wiz_zalecenia_opis'];

if ($_POST['wiz_zmien_typ']<>''){
	
	$sql="update wizyty set typ_wiz = ".$_POST['zm_typ_wiz']." where id = ".$_SESSION['wyb_wiz_ed'];
	mysql_query($sql);
	#echo $sql;
	$_SESSION['grupa_realiz_wiz']=get_name ('sl_uslugi', $_POST['zm_typ_wiz'], 'id', 'id_grupy');
	logg($sql, $_SESSION['u']);
	}

if ($_POST['wyb_pac_del']) {
		foreach ($_POST['wyb_pac_del'] as $i => $w){
		$del_pac=$i;
		}
		
	}

	if ($_POST['wyb_pac_del']) {
		foreach ($_POST['wyb_pac_del'] as $i => $w){
		$_SESSION['wyb_pac_id']=$i;
	}
}
	
if ($_POST['wiz_wyw']) {
    $_SESSION['wiz_skad']='wiz_wyw';
}

if ($_POST['wiz_zlec_det']) {
    $_SESSION['wiz_zlec_det']=$_POST['wiz_zlec_det'];
}

if ($_POST['wysw_graf']) {
    $_SESSION['wysw_graf']=$_POST['wysw_graf'];
}

if ($_GET['realiz_wiz_d']){
#$sql="delete from wizyty where id =".$_GET['realiz_wiz_d'];
$sql="update wizyty set akt=0 where id =".$_GET['realiz_wiz_d'];
mysql_query($sql);
logg($sql, $_SESSION['u']);
}

if ($_POST['dod_pac']){
if ($_POST['imie']<>'') $_SESSION['imie']=$_POST['imie'];
if ($_POST['nazw']<>'') $_SESSION['nazw']=$_POST['nazw'];
if ($_POST['tel']<>'') $_SESSION['tel']=$_POST['tel'];
}

if ($_POST['wiz_zapisz']) {
	
	$opis_bad=$_SESSION['wiz_badanie_opis'];
    $sql="insert into wizyty_inf values ('".$_SESSION['realiz_wiz']."', '".$_SESSION['wiz_wyw_opis']."', '".$opis_bad."',  '".$_SESSION['wiz_zalecenia_opis']."')";
	#echo $sql;
    mysql_query($sql);
	logg($sql, $_SESSION['u']);
	
	
	
	if ($_SESSION['wyb_lek_id']<>''){
	foreach ($_SESSION['wyb_lek_id'] as $i=>$w){
	$w=get_name ('sl_bloz', $w, 'concat(nazwa, " - ", ilosc)', 'id');
	
	$sql="insert into wizyty_leki values ('".$_SESSION['realiz_wiz']."', '".$w."')";
	mysql_query($sql);
	logg($sql, $_SESSION['u']);
	}
	}
	if ($_SESSION['wiz_zlec_det']<>''){
	foreach ($_SESSION['wiz_zlec_det'] as $i=>$w){
	$sql="insert into wizyty_zlecenia values ('".$_SESSION['realiz_wiz']."', '".$i."')";
	mysql_query($sql);
	logg($sql, $_SESSION['u']);
	}
	}
	
	

	
	if ($_SESSION['bad_wyn_jedn']<>''){
	foreach ($_SESSION['bad_wyn_jedn'] as $i=>$w){
	#$w=get_name ('sl_bloz', $w, 'concat(nazwa, " - ", ilosc)', 'id');
	foreach ($_SESSION['bad_wyn_jedn'][$i] as $in=>$wa){
	$sql="insert into wizyty_badania values ('".$_SESSION['realiz_wiz']."', '".$i."', '".$in."', '".$wa."')";
	mysql_query($sql);
	logg($sql, $_SESSION['u']);
	}
	}
	}
	$_SESSION['config']='panel';
	$_SESSION['tyt_okna']='Panel';
	unset($_SESSION['wyb_pac_id'], $_SESSION['wiz_zlec_det'], $_SESSION['rodz_bad'], $_SESSION['bad_wyn_jedn'], $_SESSION['wiz_wyw_opis'], $_SESSION['wiz_badanie_opis'], $_SESSION['wiz_zalecenia_opis'], $_SESSION['wyb_lek_id']);
	
$_SESSION['wyb_wiz_view']=$_SESSION['realiz_wiz'];
$_SESSION['config']='wizyty_podglad';
unset($_SESSION['realiz_wiz']);
	
	}

	
	
	if ($_POST['form_dod_z_bad']=='Zapisz'){
	$sql="insert into lab_zlec values ('', '".$_SESSION['wyb_pac_lab_id']."', '".$_POST['platnik']."', '".$_SESSION['data']."', 1)";
	mysql_query($sql);
	$id_wp_zlec=mysql_insert_id();
	logg($sql, $_SESSION['u']);
	
	foreach ($_POST['bad_lab'] as $i=>$w){
	$sql="insert into lab_zlec_det values ('".$id_wp_zlec."', '".$i."')";
	mysql_query($sql);
	logg($sql, $_SESSION['u']);
	}
	$_SESSION['config']='grafik';
	}
	
	if ($_POST['form_del_zlec']){
		foreach ($_POST['form_del_zlec'] as $i=>$w){
			$sql="update lab_zlec set akt=0 where id =".$i;
			mysql_query($sql);
			logg($sql, $_SESSION['u']);
		}	
	}


if ($_POST['wiz_badanie']) $_SESSION['wiz_skad']='wiz_badanie';
if ($_POST['wiz_popw']) $_SESSION['wiz_skad']='wiz_popw';
if ($_POST['wiz_wyniki_badan']) $_SESSION['wiz_skad']='wiz_wyniki_badan';
if ($_POST['bad_wyn_jedn']) $_SESSION['bad_wyn_jedn'][$_SESSION['rodz_bad']]=$_POST['bad_wyn_jedn'];
if ($_POST['wiz_leki']) $_SESSION['wiz_skad']='wiz_leki';
if ($_POST['wiz_zlecenia']) $_SESSION['wiz_skad']='wiz_zlecenia';
if ($_POST['wiz_zalecenia']) $_SESSION['wiz_skad']='wiz_zalecenia';
if ($_POST['rodz_bad']) $_SESSION['rodz_bad']=$_POST['rodz_bad'];


if($_GET['realiz_pac_id']) $_SESSION['wyb_pac_id']=$_GET['realiz_pac_id'];
if ($_POST['wyb_pac']) {
	foreach ($_POST['wyb_pac'] as $i => $w){
		$_SESSION['pop_wyb_pac_id']=$_SESSION['wyb_pac_id'];
		$_SESSION['wyb_pac_id']=$i;
	}
}

if ($_POST['wyb_pac_lab']) {
	foreach ($_POST['wyb_pac_lab'] as $i => $w){
		$_SESSION['pop_wyb_pac_id']=$_SESSION['wyb_pac_id'];
		$_SESSION['wyb_pac_lab_id']=$i;
	}
}

if ($_POST['wyb_wiz_view']){
foreach ($_POST['wyb_wiz_view'] as $i => $w){
		$_SESSION['wyb_wiz_view']=$i;
	}
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='wizyty_podglad';
}

if ($_POST['wyb_lek_b']) {
	foreach ($_POST['wyb_lek_b'] as $i => $w){
		$_SESSION['wyb_lek_id'][]=$i;
	}
}

if ($_POST['wy_pac']) {
    unset($_SESSION['imie'], $_SESSION['nazw'], $_SESSION['pesel'], $_SESSION['wyb_pac_id']);
}

if ($_POST['wyb_pac_ed']) {
    #unset($_SESSION['imie'], $_SESSION['nazw'], $_SESSION['pesel'], $_SESSION['wyb_pac_id']);
	$_SESSION['config']='pac_ed';
	$_SESSION['tyt_okna']='Edycja pacjenta';
	}

if ($_POST['wiz_zapisz_ed']){
#$sql="update wizyty_inf set wywiad = '".$_SESSION['wiz_wyw_opis']."', badanie = '".$_SESSION['wiz_badanie_opis']."', zalecenia = '".$_SESSION['wiz_zalecenia_opis']."' where id_wiz=".$_SESSION['wyb_wiz_ed'];

$data['icd10']=$_POST['icd10'];
$db->update("wizyty_inf_dod", $data, "id_wizyty=".$_SESSION['wyb_wiz_ed']);
unset($_SESSION['icd10']);
if ($_SESSION['grupa_realiz_wiz']==3){
		$opis_bad=$_POST['wiz_badanie_opis'].'###!!!'.$_POST['wiz_badanie_opis_bad'];
	}
	else $opis_bad=$_POST['wiz_badanie_opis'];
$sql="update wizyty_inf set wywiad = '".mysql_real_escape_string($_POST['wiz_wyw_opis'])."', badanie = '".mysql_real_escape_string($opis_bad)."', zalecenia = '".mysql_real_escape_string($_POST['wiz_zalecenia_opis'])."' where id_wiz=".$_SESSION['wyb_wiz_ed'];
#$sql=  addslashes($sql);
logg($sql, $_SESSION['u']);

#echo $sql;

mysql_query($sql);
unset ($_SESSION['wiz_wyw_opis'], $_SESSION['wiz_badanie_opis'], $_SESSION['wiz_zalecenia_opis'], $_SESSION['wiz_skad']);
$_SESSION['wyb_wiz_view']=$_SESSION['wyb_wiz_ed'];
$_SESSION['config']='wizyty_podglad';
unset($_SESSION['realiz_wiz'], $_SESSION['wiz_wart']);
}

if ($_POST['wyb_wiz_ed']) {
	$_SESSION['config']='wizyty2';
	$_SESSION['tyt_okna']='Edycja wizyty';
	$_SESSION['realiz_wiz']=1;
}

if ($_POST['admin']) {
	$_SESSION['config']='admin';
	$_SESSION['tyt_okna']='Administrator';
}

if ($_POST['dok_med']) {
	$_SESSION['config']='dok_med';
	$_SESSION['tyt_okna']='Zewn�trzna dokumentacja medyczna';
	
}




if ($_POST['wiz_anuluj']) {
    unset($_SESSION['realiz_wiz'], $_SESSION['wyb_pac_id'], $_SESSION['wyb_lek_id'], $_SESSION['wiz_wyw_opis'], $_SESSION['wiz_badanie_opis'], $_SESSION['wiz_zalecenia_opis']);
	$_SESSION['config_pop']=$_SESSION['config'];
    $_SESSION['config']='panel';
}

if ($_POST['grafik']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='grafik';
	$_SESSION['tyt_okna']='Grafik';
}

if ($_POST['wydruki']) {
	if ($_SESSION['config']<>'wydruki') $_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='wydruki';
	$_SESSION['tyt_okna']='Wydruki';
}

if ($_POST['form_ed_pac']){

$sql="update pac set pac_pesel='".$_POST['pac_pesel']."', pac_nazwisko='".$_POST['pac_naz']."', pac_dataur='".$_POST['pac_dataur']."', pac_imie='".$_POST['pac_imie']."', pac_adrm='".$_POST['pac_miasto']."', pac_adrk='".$_POST['pac_kod']."', pac_adru='".$_POST['pac_ulica']."', pac_adrd='".$_POST['pac_nrdom']."', pac_adrl='".$_POST['pac_nrlok']."', pac_telefon='".$_POST['pac_tel']."', pac_telefon2='".$_POST['pac_tel2']."', pac_telefon3='".$_POST['pac_tel3']."', osoba_kont='".$_POST['osoba_kont']."',email='".$_POST['email']."', osoba_kont_tel='".$_POST['osoba_kont_tel']."', polisa='".$_POST['pac_polisa']."', zlecenie='".$_POST['pac_zlecenie']."' , platnik='".$_POST['platnik']."', stymulator='".$_POST['stymulator']."', oswiadczenie='".implode("|", $_POST['oswiadczenie'])."' where id=".$_POST['pac_id'];
	#echo $sql;
	mysql_query($sql);
	logg($sql, $_SESSION['u']);
	$_SESSION['wyb_pac_id']=$_POST['pac_id'];
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='pacjenci';
	$_SESSION['tyt_okna']='Pacjenci';
}

if ($_POST['grafik']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='grafik';
	$_SESSION['tyt_okna']='Grafik';
	unset($_SESSION['zap_pac_na_wiz_czas'], $_SESSION['dod_pac_lab']);
}
if ($_POST['grafik_dod_b']){
	#$sqll="select * from grafik where  grafik.data_od >= '".$_POST['grafik_dod']['d_od']."' and  grafik.data_do <= '".$_POST['grafik_dod']['d_do']."' and grafik.g_od >= '".$_POST['grafik_dod']['g_od']."' and grafik.g_do <= '".$_POST['grafik_dod']['g_do']."' and id_gab=".$_SESSION['wyb_gab'];
	
	$sqll="select * from grafik where  

(  (grafik.data_od<='".$_POST['grafik_dod']['d_od']."' and grafik.data_do>='".$_POST['grafik_dod']['d_do']."') or (grafik.data_od>='".$_POST['grafik_dod']['d_od']."' and grafik.data_od<='".$_POST['grafik_dod']['d_do']."') or (grafik.data_do>='".$_POST['grafik_dod']['d_od']."' and grafik.data_do<='".$_POST['grafik_dod']['d_do']."')   )

and id_gab=".$_SESSION['wyb_gab'];
	
	#echo $sqll;
	$result=mysql_query($sqll);
	$ile=@mysql_numrows($result);
	if ($ile==0){
	foreach ($_POST['grafik_dod']['dni'] as $i=>$w){
	$dni[]=$w;
	}
		$dni_z=implode(';', $dni);
	
     $sql="insert into grafik values ('".$_POST['grafik_dod']['d_od']."', '".$_POST['grafik_dod']['d_do']."', '".$_POST['grafik_dod']['g_od']."', '".$_POST['grafik_dod']['g_do']."', '".$_POST['grafik_dod']['interwal']."', '".$_SESSION['dod_graf_lek']."', '".$dni_z."', '".$_POST['grafik_dod']['gab']."')";   
     logg($sql, $_SESSION['u']);
	 #echo $sql;
     mysql_query($sql);
	 $_SESSION['config_pop']=$_SESSION['config'];
     $_SESSION['config']='grafik';
	 $_SESSION['tyt_okna']='Grafik';
	}
	else $_SESSION['dod_graf_error']='Nie mo�na doda� grafiku, grafik w podanym terminie ju� istnieje'; 
}
if ($_POST['dod_szablon_opis']){
$sql="insert into sl_szablony values ('', '".$_POST['dod_szablon_opis']."', '".$_SESSION['wyb_gab']."', '".$_SESSION['s']."' ,'1')";
#echo $sql;
mysql_query($sql);
logg($sql, $_SESSION['u']);
#$_SESSION['config_pop']=$_SESSION['config'];
#$_SESSION['config']='szablony';
#$_SESSION['tyt_okna']='Szablony opisu';
}
if ($_POST['dod_grafik']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='dod_grafik';
	$_SESSION['tyt_okna']='Dodawanie grafiku';
}
if ($_POST['dod_szablon']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='dod_szablon';
	$_SESSION['tyt_okna']='Dodawanie szablonu';
}

if ($_POST['grafik_v2']) {
	$_SESSION['config']='grafik_nowy';
	$_SESSION['tyt_okna']='Nowy Grafik';
}

if ($_POST['panel']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='panel';
	$_SESSION['tyt_okna']='Panel';
	unset($_SESSION['zap_pac_na_wiz_czas'], $_SESSION['dod_pac_lab']);
}

if ($_SESSION['dod_pac_lab']  && $_POST['wyb_pac_lab']){
		$_SESSION['config']='zlec_lab';
		$_SESSION['tyt_okna']='Zlecenie do laboratorium';
}
if ($_SESSION['zap_pac_na_wiz_czas'] && $_SESSION['wyb_pac_id'] && $_SESSION['wyb_gab'] && $_POST['wyb_pac']){
	$wyb_pac_new=$_SESSION['wyb_pac_id'];
	if ($_SESSION['zap_pac_na_wiz_czas']=='bez_cz') {
	$czas_wizyty=$_POST['zap_pac_na_wiz'][$wyb_pac_new];
	$_SESSION['config']='grafik';
	}
	else {
	$czas_wizyty=$_SESSION['zap_pac_na_wiz_czas'];
	$_SESSION['config']='grafik';
	}
	$sql="insert into wizyty values ('', '".$_SESSION['data']." ".$czas_wizyty."', ".$_SESSION['wyb_pac_id'].", ".$_SESSION['wyb_gab'].", ".$_SESSION['uzytk']['id'].", ".$_POST['typ_wiz'][$wyb_pac_new].", '1')";
        //$pac_pesel = get_name('pac', $_SESSION['wyb_pac_id'], 'pac_pesel', 'id');
	//echo $pac_pesel;
        
        $ewus_odp = check_pac_ubezp($_SESSION['wyb_pac_id']);
        //print_r($ewus_odp);
	logg($sql, $_SESSION['u']);
	mysql_query($sql);
	$_SESSION['config_pop']=$_SESSION['config'];
	#$_SESSION['config']='grafik';
	unset($_SESSION['zap_pac_na_wiz_czas'], $_SESSION['dod_pac_lab']);
}
if ($_POST['wyb_gab']) {
	$_SESSION['wyb_gab']=$_POST['wyb_gab'];
}
if ($_POST['pacjenci']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='pacjenci';
	$_SESSION['tyt_okna']='Pacjenci';
	unset($_SESSION['zap_pac_na_wiz_czas'], $_SESSION['dod_pac_lab']);
}

if ($_GET['wiz_szablon']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='wizyty2';
	$_SESSION['tyt_okna']='Wizyta';
}
if ($_GET['realiz_wiz']){
    $_SESSION['realiz_wiz']=$_GET['realiz_wiz'];
	
}

if ($_POST['wizyta']||$_GET['realiz_wiz']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='wizyty2';
	$_SESSION['tyt_okna']='Wizyta';
	#unset($_SESSION['zap_pac_na_wiz_czas'], $_SESSION['wiz_badanie_opis'], $_SESSION['wiz_wyw_opis'], $_SESSION['wiz_skad'], $_SESSION['wiz_zalecenia_opis']);
}

#if ($_POST['wizyta2']||$_GET['realiz_wiz']) {
#	$_SESSION['config']='wizyty';
#	$_SESSION['tyt_okna']='Wizyta';
#	unset($_SESSION['zap_pac_na_wiz_czas'], $_SESSION['wiz_badanie_opis'], $_SESSION['wiz_wyw_opis'], $_SESSION['wiz_skad']);
#}

if ($_GET['zap_pac_na_wiz']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='pacjenci';
	$_SESSION['zap_pac_na_wiz_czas']=$_GET['zap_pac_na_wiz'];
	#unset($_SESSION['wyb_pac_id']);
}

if ($_POST['dod_pac_lab']) {
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='pacjenci';
	$_SESSION['dod_pac_lab']=$_POST['dod_pac_lab'];
	$_SESSION['wyb_pac_id']=$_SESSION['wyb_pac_lab_id'];
	#unset($_SESSION['wyb_pac_id']);
}

if ($_POST['wyb_pac']) {
	foreach ($_POST['wyb_pac'] as $i => $w){
		$_SESSION['wyb_pac_id']=$i;
	}
}

if ($_POST['form_dod_pac']){
	$sql="insert into pac values ('', '".$_POST['pac_pesel']."', '".$_POST['pac_imie']."', '".$_POST['pac_naz']."', '".$_POST['pac_dataur']."', '".$_POST['pac_miasto']."', '".$_POST['pac_kod']."', '".$_POST['pac_ulica']."', '".$_POST['pac_nrdom']."', '".$_POST['pac_nrlok']."', '".$_POST['pac_tel']."', '".$_POST['pac_tel2']."', '".$_POST['pac_tel3']."', '".$_POST['osoba_kont']."', '".$_POST['osoba_kont_tel']."','".$_POST['email']."', '".$_POST['pac_polisa']."', '".$_POST['pac_zlecenie']."', '".$_POST['platnik']."', '".$_POST['stymulator']."', '".implode("|", $_POST['oswiadczenie'])."', 1)";
	#echo $sql;
	mysql_query($sql);
	logg($sql, $_SESSION['u']);
	$_SESSION['imie']=$_POST['pac_imie'];
	$_SESSION['nazw']=$_POST['pac_naz'];
	$_SESSION['pesel']=$_POST['pac_pesel'];
	$id_wp_pac=mysql_insert_id();
	$_SESSION['wyb_pac_id']=$id_wp_pac;
	$_SESSION['config_pop']=$_SESSION['config'];
	$_SESSION['config']='pacjenci';
	$_SESSION['tyt_okna']='Pacjenci';
}

if ($_POST['wiz_szablon']){
	$_SESSION['config_pop']=$_SESSION['config'];
    $_SESSION['config']='szablony';
	$_SESSION['tyt_okna']='Szablony opisu';
}



if ($_POST['logout']) {
session_unset();
include('login.php');
}


if ($_POST['wyb_pac'] && $_SESSION['zap_pac_na_wiz_czas']) {
	$_SESSION['config']='grafik';
}
if ($_SESSION['config'] && $_SESSION['uzytk']){
$sql="select user_gab.id_gab, sl_gab.nazwa from user_gab, sl_gab where sl_gab.id=user_gab.id_gab and user_gab.id_user= ".$_SESSION['uzytk']['id']." order by sl_gab.nazwa";
$result=mysql_query($sql);
	#logg($sql, $_SESSION['u']);
while($row = mysql_fetch_array($result))
{
$list_gab[$row[0]]=$row[1];
if ($_SESSION['wyb_gab']=='') $_SESSION['wyb_gab']=$row[0];
}

if ($_GET['gabg']) $_SESSION['wyb_gab']=$_GET['gabg'];

if ($_GET['data']) $_SESSION['data']=$_GET['data'];




echo '<table bgcolor="#D9E0E7" width="90%" height="80%" align="center" border="0" cellspacing="0" cellpadding="0">';
echo '<td width="20%" valign=top align=center>';
echo '<table border=0>';
echo '<form action="index.php" method="POST">';


if ($_SESSION['realiz_wiz']=='') {
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/blue.png); background-repeat: repeat-x; color: #FFFFFF; " value="Panel" name="panel"></td></tr>';
}

if ($_SESSION['realiz_wiz']=='') {
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/blue.png); background-repeat: repeat-x; color: #FFFFFF; " value="Grafik" name="grafik"></td></tr>';
}

#if ($_SESSION['realiz_wiz']=='') {
#echo '<tr><td height=30><input ';
#echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/green.png); background-repeat: repeat-x; color: #FFFFFF; " value="Grafik nowy" #name="grafik_v2"></td></tr>';
#}


if ($_SESSION['realiz_wiz']=='') {
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/blue.png); background-repeat: repeat-x; color: #FFFFFF; " value="Pacjenci" name="pacjenci"></td></tr>';
}

if ($_SESSION['uzytk']['id_grupy']=='1') {
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/green.png); background-repeat: repeat-x; color: #FFFFFF; " value="Administrator" name="admin"></td></tr>';
}

if ($_SESSION['realiz_wiz']<>'') {
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/blue.png); background-repeat: repeat-x; color: #FFFFFF; " value="Wizyta" name="wizyta"></td></tr>';
}
if ($_SESSION['realiz_wiz']=='aaa' || $_SESSION['config'] == 'wizyty_podglada') {
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/green.png); background-repeat: repeat-x; color: #FFFFFF; " value="Zewn. Dok. Med." name="dok_med"></td></tr>';
}
echo '<tr><td height=30><input ';
echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/blue.png); background-repeat: repeat-x; color: #FFFFFF; " value="Wydruki" name="wydruki"></td></tr>';

#echo '<tr><td height=30><input ';
#echo 'type=SUBMIT style="width: 130px;height: 22px;background-image: url(./img/red.png); background-repeat: repeat-x; color: #FFFFFF; " value="Powr�t" name="powrot"></td></tr>';

echo '<tr><td height=30><input type=SUBMIT style="width: 130px;height: 22px;background-color: #AD1412; background-repeat: repeat-x; color: #FFFFFF; " value="Wyloguj" name="logout"></td></tr>';
echo '</form>';
echo '<tr><td height=30>';
form_auto_submit('index.php','wyb_gab', $list_gab, $_SESSION['wyb_gab']);
echo '</td></tr>';

echo '</table>';
echo '<td>';
echo '<td width="15"></td>
        <td width="80%" valign=top><br>';
if ($_SESSION['wyb_pac_id']<>$_SESSION['pop_wyb_pac_id']){
	#echo 'Wybrany pacjent:';
	$sql="select * from pac where id = ".$_SESSION['wyb_pac_id'];
	$result=mysql_query($sql);
	logg($sql, $_SESSION['u']);
	$pac_det = @mysql_fetch_array($result);
	echo '<b>'.$pac_det['pac_nazwisko'].' '.$pac_det['pac_imie'].'-'.$pac_det['pac_pesel'].'</b>';
	$_SESSION['imie']=$pac_det['pac_imie'];
	$_SESSION['nazw']=$pac_det['pac_nazwisko'];
	$_SESSION['pesel']=$pac_det['pac_pesel'];
	$_SESSION['pop_wyb_pac_id']=$_SESSION['wyb_pac_id'];
}
else {
	
	echo '<b>'.$_SESSION['nazw'].' '.$_SESSION['imie'].'-'.$_SESSION['pesel'].'</b>';
	
}
echo '<FIELDSET><LEGEND>';
echo '<b>'.$_SESSION['tyt_okna'].'</b>';
echo '</LEGEND>';
if ($_POST['powrot']<>'') $_SESSION['config']=$_SESSION['config_pop'];
if ($_SESSION['config'] && $_SESSION['uzytk'])include($_SESSION['config'].'.php');
echo '</FIELDSET>';
echo '</td>';
echo '</tr>';
echo '</table>';
}
if($_GET['debug']==1) $_SESSION['debug']=1;
if ($_SESSION['debug']==1) zmienne();
?>